#include <zlib/lib/Ink_atomic.h>
#include <zlib/lib/Ink_pthread.h>
#include <iostream>

using namespace std;

int64_t g_number = 0;
int64_t g_atomic_number = 0;

void *test(void *arg)
{
	for(int64_t i = 0; i < 1000000000; i++) {
		g_number++;
		ink_atomic_increment(&g_atomic_number, 1);
	}

	return NULL;
}

int main()
{
	int a = 10;
	int b = ink_atomic_swap(&a, 20);
	cout << a << endl;
	cout << b << endl;
	cout << "-------------" << endl;

	bool res = ink_atomic_cas(&a, 10, 30);
	if(res) {
		cout << "cas success:" << a << endl;
	}else{
		cout << "cas faild:" << endl;
	}

	res = ink_atomic_cas(&a, 20, 30);
	if(res) {
		cout << "cas success:" << a << endl;
	}else{
		cout << "cas faild" << endl;
	}

	cout << "----------------" << endl;

	ink_thread tid = ink_thread_create(test, NULL);
	for(int64_t i = 0; i < 1000000000; i++) {
		g_number++;
		ink_atomic_increment(&g_atomic_number, 1);
	}
	ink_thread_join(tid, NULL);
	cout << g_number << endl;
	cout << g_atomic_number << endl;
}
